protoc-grpcio
A programmatic API to the grpc-rs compiler.
Requirements
- You must have Google's Protocol Buffer compiler (
protoc
) installed and inPATH
.
Example build.rs
For a project laid out like so:
$ tree
.
├── build.rs
├── Cargo.toml
└── src
├── client.rs
├── protos
│ ├── example
│ │ └── diner.proto
│ └── mod.rs
└── server.rs
3 directories, 7 files
The build.rs
might look like:
extern crate protoc_grpcio;
Example Cargo.toml
And the Cargo.toml
might look like:
[]
# ...
= "build.rs"
[]
= "protos"
= "src/protos/mod.rs"
[[]]
= "server"
= "src/server.rs"
[[]]
= "client"
= "src/client.rs"
[]
= "0.1.16"
= "0.4.3"
= "~2"
[]
= "1.0.2"
You can inspect this example under example/
by compiling and running the example
server in one shell session:
cargo run --manifest-path example/Cargo.toml --bin server
...
Finished dev [unoptimized + debuginfo] target(s) in 27.97 secs
Running `example/target/debug/server`
listening on 127.0.0.1:34431
And then running the client in another:
$ cargo run --manifest-path example/Cargo.toml --bin client 34431
...
Finished dev [unoptimized + debuginfo] target(s) in 1.28 secs
Running `example/target/debug/client 34431`
Ate items: SPAM items: EGGS and got charged $0.30
Credits
Credit to both the TiKV project developers for (grpc-rs) and Stepan Koltsov (@stepancheg, rust-protobuf) for their amazing work bringing Protocol Buffers and gRPC support to Rust.